Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Checking with Array[index] multiple times vs setting it a variable and using it - JAVASCRIPT/NODE.JS

I have a bunch of if statements and setting/adding different props into my array. My javascript code is like;

for(var key in animals){

if(animals[key].eyesColor == "blue"){

  animals[key].hairColor = "yellow"  
  ...

  ...

  } 
}

As I checked, I'm using 78 times animals[key].props And my array probably contains more than 1000 items.

Should I set the animal[key] to a variable and then set back this variable to my sample array at the end of my code? In this way can I improve the performance?

for(var key in animals){

let animal = animals[key]

if(animal.eyesColor == "blue"){

  animal.hairColor = "yellow"

  ...
  ...
  }

animals[key] = animal

}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!